package com.xiaoping.app;

import com.xiaoping.base.UnionFind;

public class App20180328 {

public static void main(String[] args) {

    long beginTime = System.currentTimeMillis();
    int size = 10000000;
    // Step 1: init()
    UnionFind uf = new UnionFind(size);

    // Step 2: union()
    uf.union(1,2);
    uf.union(3,4);
    uf.union(0,9);
    uf.union(4,7);
    uf.union(6,5);
    uf.union(5,8);
    uf.union(3,9);
    uf.union(1,8);

    // Step 3: find()
    System.out.println(uf.find(0));     // 9
    System.out.println(uf.find(1));     // 5
    System.out.println(uf.find(2));     // 5
    System.out.println(uf.find(3));     // 9
    System.out.println(uf.find(4));     // 9
    System.out.println(uf.find(5));     // 5
    System.out.println(uf.find(6));     // 5
    System.out.println(uf.find(7));     // 9
    System.out.println(uf.find(8));     // 5
    System.out.println(uf.find(9));     // 9

    // Step 4: isConnected
    System.out.println(uf.isConnected(0,1));    // false
    System.out.println(uf.isConnected(1,2));    // true
    System.out.println(uf.isConnected(3,4));    // true
    System.out.println(uf.isConnected(5,6));    // true
    System.out.println(uf.isConnected(7,8));    // false
    System.out.println(uf.isConnected(8,9));    // false
    System.out.println(uf.isConnected(2,4));    // false
    System.out.println(uf.isConnected(3,5));    // false
    System.out.println(uf.isConnected(5,6));    // true
    System.out.println(uf.isConnected(7,9));    // true

    long endTime = System.currentTimeMillis();

    System.out.println("耗时：" + (endTime - beginTime) + "ms");

}
}
